const { user, userAuth, kind, good, translation } = require('../models/index')
const authController = require('./authController')
const tokenController = require('./tokenController')
const errorHelper = require('../util/errorHelper')
const uuidv5 = require('uuid/v5')
const bcrypt = require('bcrypt')
const tokenGenerator = require('../util/tokenGenerator')

class UserController {
  constructor() {
    // empty
  }

  async getDetailByUserId(userId, isTokenValid) {
    const userDetail = await user.findAll({
      where: {
        userId
      },
      include: isTokenValid ? [{ model: userAuth, as: 'auths', attributes: ['identityType', 'identifier'] }] : []
    })
    if (!userDetail.length) {
      throw errorHelper(400, 'user not exist')
    }
    return userDetail[0]
  }

  async saveInfo(userInfo) {
    const result = await user.update(userInfo, { where: { shopId: userInfo.userId } })
    if (!result) {
      throw errorHelper(400, 'field error')
    }
    return result
  }
  // static async findAll() {
  //   await shop.findAll()
  // }
}

module.exports = new UserController()
